{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b7622da6",
   "metadata": {},
   "source": [
    "* week 5\n",
    "* 记录人:liyi\n",
    "* 记录时间:2023/3/20\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "42c975e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679282743,81c019bd-33f0-470c-9961-fd7df6e885bc', 'time_used': 368, 'confidence': 97.389, 'thresholds': {'1e-3': 62.327, '1e-4': 69.101, '1e-5': 73.975}, 'faces1': [{'face_token': '4d27ca1d796b552ecef97f7fc8bfeb6e', 'face_rectangle': {'top': 103, 'left': 376, 'width': 103, 'height': 103}}], 'faces2': [{'face_token': 'e53ec05319b0e4c42355100323e31288', 'face_rectangle': {'top': 103, 'left': 376, 'width': 103, 'height': 103}}], 'image_id1': 'w8eW9h8TC2ynkym7aYdPww==', 'image_id2': 'w8eW9h8TC2ynkym7aYdPww=='}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸对比\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f_01 = open('李.jpeg', 'rb')\n",
    "img = base64.b64encode(f_01.read())\n",
    "f_02 = open('R-C (1).jpg', 'rb')\n",
    "img = base64.b64encode(f_02.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload = {\n",
    "    'api_key':'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov',\n",
    "    'api_secret':'Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3',\n",
    "    'image_base64_1':img,\n",
    "    'image_base64_2':img,\n",
    "    'return_attributes':'request_id,thresholds,confidence'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data = payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "90d98df5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'faceset_token': 'a13859f494957f050a266bc81e1c7d7a', 'time_used': 195, 'face_count': 0, 'face_added': 0, 'request_id': '1679283425,16a8ac85-4bba-42fa-86e7-fd7add2377de', 'outer_id': '', 'failure_detail': []}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests\n",
    "'''\n",
    "人脸数据库创建\n",
    "'''\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\"\n",
    "# 请求参数\n",
    "params = {\n",
    "    'api_key':'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov',\n",
    "    'api_secret':'Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3',\n",
    "    \"display_name\":\"广州南方学院宿舍楼3栋\"\n",
    "}\n",
    "    \n",
    "   \n",
    "response = requests.post(request_url, data = params)\n",
    "\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "a53f5894",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'faceset_token': 'a13859f494957f050a266bc81e1c7d7a', 'tags': '', 'time_used': 138, 'user_data': '', 'display_name': '广州南方学院宿舍楼3栋', 'face_tokens': [], 'face_count': 0, 'request_id': '1679283711,9a41c2d3-4035-49fb-bf98-e4135d914d14', 'outer_id': ''}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests\n",
    "'''\n",
    "人脸数据集合详情查询\n",
    "'''\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "# 请求参数\n",
    "params = {\n",
    "    'api_key':'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov',\n",
    "    'api_secret':'Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3',\n",
    "    \"faceset_token\":\"a13859f494957f050a266bc81e1c7d7a\"\n",
    "}\n",
    "    \n",
    "   \n",
    "response = requests.post(request_url, data = params)\n",
    "\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "67d8a044",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (<ipython-input-23-718da4950f76>, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-23-718da4950f76>\"\u001b[1;36m, line \u001b[1;32m13\u001b[0m\n\u001b[1;33m    f = open('3栋迪丽热巴.jpg,'rb')\u001b[0m\n\u001b[1;37m                              ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "人脸检查\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('3栋迪丽热巴.jpg,'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "params = {\n",
    "    'api_key':'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov',\n",
    "    'api_secret':'Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3',\n",
    "    'image_base64_1':img,\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data = payload, headers=headers)\n",
    "print (response.json())\n",
    "print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ef56162",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "96691526",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
